package My.example.service.impl;

import My.example.dao.AccountDao;
import My.example.domain.Account;
import My.example.service.AccountService;
import My.example.service.logser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service

public class AccountServiceImpl implements AccountService {
    @Autowired
    private AccountDao accountDao;

    @Autowired
    private logser logService;

    public void save(Account account) {
        accountDao.save(account);
    }

    public void update(Account account){
        accountDao.update(account);
    }

    public void delete(Integer id) {
        accountDao.delete(id);
    }

    public Account findById(Integer id) {
        return accountDao.findById(id);
    }

    public List<Account> findAll() {
        return accountDao.findAll();
    }
    public void outMoney(String name, Double money) {
        accountDao.outMoney(name,money);
    }
    public void inMoney(String name, Double money) {
        accountDao.inMoney(name,money);
    }

    public void transfer(String out,String in ,Double money) {
        try{
            accountDao.outMoney(out,money);
            //int i = 1/0;
            accountDao.inMoney(in,money);
        }finally {
            logService.log(out,in,money);
        }

    }


}
